using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CthulhuDomain
{
  public class SpriteBatchAdapter : ISpriteBatch
  {
    #region private

    private readonly SpriteBatch Adaptee;
    private GraphicsDevice _graphicsDevice;

    #endregion

    #region public

    public GraphicsDevice GraphicsDevice {
      get { return _graphicsDevice; }
      set { _graphicsDevice = value; }
    }

    #endregion

    public SpriteBatchAdapter(GraphicsDevice GraphicsDevice) {
      this.GraphicsDevice = GraphicsDevice;
      Adaptee = new SpriteBatch(GraphicsDevice);
    }

    
    public void Begin() {
      Adaptee.Begin();
    }

    public void End() {
      Adaptee.End();
    }

    public void Draw(IGraphicResource Texture, IVector2 Position, IRectangle rectangle, IColor color) {
      Adaptee.Draw(((Texture2DAdapter)Texture).Adaptee,
                   ((Vector2Adapter)Position).Adaptee,
                   ((RectangleAdapter)rectangle).Adaptee,
                   ((ColorAdapter)color).Adaptee);
    }

    public void Draw(IGraphicResource Texture, IVector2 Position, IRectangle rectangle, IColor color, IVector2 Scale, int LayerDepth) {
      Adaptee.Draw(((Texture2DAdapter)Texture).Adaptee,
                   ((Vector2Adapter)Position).Adaptee,
                   ((RectangleAdapter)rectangle).Adaptee,
                   ((ColorAdapter)color).Adaptee,
                   0, new Vector2(0, 0), ((Vector2Adapter)Scale).Adaptee, SpriteEffects.None, LayerDepth);
    }

    public void DrawString(IGraphicResource font, string text, IVector2 Position, IColor color) {
      Adaptee.DrawString(((SpriteFontAdapter)font).Adaptee,
                         text,
                         ((Vector2Adapter)Position).Adaptee,
                         ((ColorAdapter)color).Adaptee);

    }

    public void DrawString(IGraphicResource font, string text, IVector2 position, IColor color, float scale, int layerDepth) {
      Adaptee.DrawString(((SpriteFontAdapter)font).Adaptee,
                         text,
                         ((Vector2Adapter)position).Adaptee,
                         ((ColorAdapter)color).Adaptee,0,new Vector2(0,0),1, SpriteEffects.None, layerDepth );

    }
    
    public void DrawString(IGraphicResource font, string text, IVector2 position, IColor color,float rotation, float scale, int layerDepth) {
      Adaptee.DrawString(((SpriteFontAdapter)font).Adaptee,
                         text,
                         ((Vector2Adapter)position).Adaptee,
                         ((ColorAdapter)color).Adaptee,
                         rotation,
                         new Vector2(0,0),1, SpriteEffects.None, layerDepth );

    }

  }
}